﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HIWSystem.Common;
using HIWSystem.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace HIWSystem.ViewModel
{
    [MetadataType(typeof(ReleaseWOViewModel))]
    public class ReleaseWOViewModel : ViewModelBase, IDataErrorInfo
    {
        #region 属性

        //用于判断是不是第一次触发过滤，是则备份原始数据源
        private bool isFirstFilterPN = true;

        private bool isFirstFilterFlow = true;

        //用于再ComboBox控件中输入内容过滤时备份原始的数据源
        //当没有输入内容时恢复到备份的原始数据源
        private ObservableCollection<PartNumberEntity> backupPNs = null;

        private ObservableCollection<RoutingEntity> backupFlows = null;

        /// <summary>
        /// 表单验证错误集合
        /// </summary>
        private Dictionary<String, String> dataErrors = new Dictionary<String, String>();

        private ObservableCollection<PartNumberEntity> pns;

        /// <summary>
        /// 机种数据源
        /// </summary>
        public ObservableCollection<PartNumberEntity> PNs
        {
            get { return pns; }
            set { pns = value; this.RaisePropertyChanged(() => PNs); }
        }

        private ObservableCollection<RoutingEntity> flows;

        /// <summary>
        /// 流程数据源
        /// </summary>
        public ObservableCollection<RoutingEntity> Flows
        {
            get { return flows; }
            set { flows = value; this.RaisePropertyChanged(() => Flows); }
        }

        private RoutingEntity selectedRouting;

        /// <summary>
        /// ComboBox选中的流程实体
        /// </summary>
        public RoutingEntity SelectedRouting
        {
            get { return selectedRouting; }
            set { selectedRouting = value; this.RaisePropertyChanged(() => SelectedRouting); }
        }

        private PartNumberEntity selectedPartNumber;

        /// <summary>
        /// ComboBox选中的机种实体
        /// </summary>
        public PartNumberEntity SelectedPartNumber
        {
            get { return selectedPartNumber; }
            set { selectedPartNumber = value; this.RaisePropertyChanged(() => SelectedPartNumber); }
        }

        private string Wo = "";

        /// <summary>
        /// 工单
        /// </summary>
        [Required]
        public string WO
        {
            get { return Wo; }
            set { Wo = value; this.RaisePropertyChanged(() => WO); }
        }

        private string woDescription;

        /// <summary>
        /// 工单描述
        /// </summary>
        public string WODescription
        {
            get { return woDescription; }
            set { woDescription = value; this.RaisePropertyChanged(() => WODescription); }
        }

        private string ownerManufacturer;

        /// <summary>
        /// 所属厂商
        /// </summary>
        [Required]
        public string OwnerManufacturer
        {
            get { return ownerManufacturer; }
            set { ownerManufacturer = value; this.RaisePropertyChanged(() => OwnerManufacturer); }
        }

        private string pn = "";

        /// <summary>
        /// 选择的机种
        /// </summary>
        [Required]
        public string PN
        {
            get { return pn; }
            set { pn = value; this.RaisePropertyChanged(() => PN); }
        }

        private string flow = "";

        /// <summary>
        /// 选中的流程
        /// </summary>
        [Required]
        public string Flow
        {
            get { return flow; }
            set { flow = value; this.RaisePropertyChanged(() => Flow); }
        }

        private bool isOpenComboPNDropDown = false;

        /// <summary>
        /// 是否打开机种下拉框选项卡
        /// </summary>
        public bool IsOpenComboPNDropDown
        {
            get { return isOpenComboPNDropDown; }
            set { isOpenComboPNDropDown = value; this.RaisePropertyChanged(() => IsOpenComboPNDropDown); }
        }

        private bool isOpenComboRoutingDropDown = false;

        /// <summary>
        /// 是否打开流程下拉框选项卡
        /// </summary>
        public bool IsOpenComboRoutingDropDown
        {
            get { return isOpenComboRoutingDropDown; }
            set { isOpenComboRoutingDropDown = value; this.RaisePropertyChanged(() => IsOpenComboRoutingDropDown); }
        }

        private string searchPNText;

        /// <summary>
        /// 机种下拉框输入的搜索内容
        /// </summary>
        public string SearchPNText
        {
            get { return searchPNText; }
            set { searchPNText = value; this.RaisePropertyChanged(() => SearchPNText); }
        }

        private string searchFlowText;

        /// <summary>
        /// 流程下拉框输入的搜索内容
        /// </summary>
        public string SearchFlowText
        {
            get { return searchFlowText; }
            set { searchFlowText = value; this.RaisePropertyChanged(() => SearchFlowText); }
        }

        private Visibility isVisibleLoading = Visibility.Collapsed;

        /// <summary>
        /// 是否显示加载按钮
        /// </summary>
        public Visibility IsVisibleLoading
        {
            get { return isVisibleLoading; }
            set { isVisibleLoading = value; this.RaisePropertyChanged(() => IsVisibleLoading); }
        }

        private string WOcount;

        /// <summary>
        /// 工单数量
        /// </summary>
        [RegularExpression(@"^[1-9][0-9]{0,4}$", ErrorMessage = "请输入1-99999]之间的数字")]
        public string WOCount
        {
            get { return WOcount; }
            set { WOcount = value; this.RaisePropertyChanged(() => WOCount); }
        }

        private string snFormat;

        /// <summary>
        ///系统定义的序列号格式
        /// </summary>
        public string SnFormat
        {
            get { return snFormat; }
            set { snFormat = value; this.RaisePropertyChanged(() => SnFormat); }
        }

        private string unitCode;

        /// <summary>
        /// 料号
        /// </summary>
        public string UnitCode
        {
            get { return unitCode; }
            set { unitCode = value; this.RaisePropertyChanged(() => UnitCode); }
        }

        private int kitCount;

        /// <summary>
        /// 子键数量
        /// </summary>
        public int KitCount
        {
            get { return kitCount; }
            set { kitCount = value; this.RaisePropertyChanged(() => KitCount); }
        }

        private int printCopiesNum;

        /// <summary>
        /// 打印的份数
        /// </summary>
        public int PrintCopiesNum
        {
            get { return printCopiesNum; }
            set { printCopiesNum = value; this.RaisePropertyChanged(() => PrintCopiesNum); }
        }

        private string pnType;

        public string PNType
        {
            get { return pnType; }
            set { pnType = value; this.RaisePropertyChanged(() => PNType); }
        }

        private string customStartSn = "";

        /// <summary>
        /// 自定义起始序列号
        /// </summary>
        public string CustomStartSn
        {
            get { return customStartSn; }
            set { customStartSn = value; this.RaisePropertyChanged(() => CustomStartSn); }
        }

        private bool isEnabledReleaseButton = false;

        /// <summary>
        /// 是否启用释放按钮
        /// </summary>
        public bool IsEnabledReleaseButton
        {
            get { return isEnabledReleaseButton; }
            set { isEnabledReleaseButton = value; this.RaisePropertyChanged(() => IsEnabledReleaseButton); }
        }

        private bool isEnabledVerifyButton = true;

        /// <summary>
        /// 是否启用验证按钮
        /// </summary>
        public bool IsEnabledVerifyButton
        {
            get { return isEnabledVerifyButton; }
            set { isEnabledVerifyButton = value; this.RaisePropertyChanged(() => IsEnabledVerifyButton); }
        }

        private ObservableCollection<WOEntity> WOsource;

        /// <summary>
        /// 工单信息资源
        /// </summary>
        public ObservableCollection<WOEntity> WOSource
        {
            get { return WOsource; }
            set { WOsource = value; this.RaisePropertyChanged(() => WOSource); }
        }

        public string this[string columnName]
        {
            get
            {
                ValidationContext vc = new ValidationContext(this, null, null);
                vc.MemberName = columnName;
                var res = new List<ValidationResult>();
                var result = Validator.TryValidateProperty(this.GetType().GetProperty(columnName).GetValue(this, null), vc, res);
                if (res.Count > 0)
                {
                    AddDic(dataErrors, vc.MemberName);
                    return string.Join(Environment.NewLine, res.Select(r => r.ErrorMessage).ToArray());
                }
                RemoveDic(dataErrors, vc.MemberName);
                return null;
            }
        }

        public string Error
        {
            get
            {
                return null;
            }
        }

        #endregion 属性

        #region 命令

        private RelayCommand filterPNCmd;

        public RelayCommand FilterPNCmd
        {
            get
            {
                if (filterPNCmd == null)
                {
                    filterPNCmd = new RelayCommand(FilterPN);
                }
                return filterPNCmd;
            }
            set { filterPNCmd = value; }
        }

        private RelayCommand filterFlowCmd;

        public RelayCommand FilterFlowCmd
        {
            get
            {
                if (filterFlowCmd == null)
                {
                    filterFlowCmd = new RelayCommand(FilterFlow);
                }
                return filterFlowCmd;
            }
            set { filterFlowCmd = value; }
        }

        private RelayCommand loadPageCmd;

        public RelayCommand LoadPageCmd
        {
            get
            {
                if (loadPageCmd == null)
                {
                    loadPageCmd = new RelayCommand(LoadPage);
                }
                return loadPageCmd;
            }
            set { loadPageCmd = value; }
        }

        private RelayCommand<string> comboPN_SelectionChangedCmd;

        public RelayCommand<string> ComboPN_SelectionChangedCmd
        {
            get
            {
                if (comboPN_SelectionChangedCmd == null)
                {
                    comboPN_SelectionChangedCmd = new RelayCommand<string>(ComboPN_SelectionChangedHandler);
                }
                return comboPN_SelectionChangedCmd;
            }
            set { comboPN_SelectionChangedCmd = value; }
        }

        private RelayCommand releaseCmd;

        public RelayCommand ReleaseCmd
        {
            get
            {
                if (releaseCmd == null)
                {
                    releaseCmd = new RelayCommand(Release);
                }
                return releaseCmd;
            }
            set { releaseCmd = value; }
        }

        private RelayCommand verifyCmd;

        public RelayCommand VerifyCmd
        {
            get
            {
                if (verifyCmd == null)
                {
                    verifyCmd = new RelayCommand(Verify);
                }
                return verifyCmd;
            }
            set { verifyCmd = value; }
        }

        private RelayCommand queryCmd;

        public RelayCommand QueryCmd
        {
            get
            {
                if (queryCmd == null)
                {
                    queryCmd = new RelayCommand(Query);
                }
                return queryCmd;
            }
            set { queryCmd = value; }
        }

        private RelayCommand<WOEntity> deleteWOCmd;

        public RelayCommand<WOEntity> DeleteWOCmd
        {
            get
            {
                deleteWOCmd = deleteWOCmd ?? new RelayCommand<WOEntity>(DeleteWO);
                return deleteWOCmd;
            }
            set { deleteWOCmd = value; }
        }

        #endregion 命令

        #region 方法

        //页面加载
        private void LoadPage()
        {
            //填充机种信息
            FillPNsToComboBox();
            //throw new NotImplementedException();
        }

        /// <summary>
        /// 验证输入的信息是否正确
        /// </summary>
        private void Verify()
        {
            string retMsg = string.Empty;//验证的信息
            if (string.IsNullOrEmpty(this.WOCount))
            {
                MessageBox.Show("输入的工单数量不能为空", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (dataErrors.Count == 0)
            {
                if (BusinessProcess.WOIsOk(this.WO.ToUpper(), out retMsg))
                {
                    this.IsEnabledReleaseButton = true;
                    this.IsEnabledVerifyButton = false;
                }
                else
                {
                    MessageBox.Show(retMsg, "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("必填项输入的信息有误", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        private void Release()
        {
            OnReleasingAsync();
        }

        /// <summary>
        /// 释放工单
        /// </summary>
        private async void OnReleasingAsync()
        {
            if (dataErrors.Count == 0)
            {
                string retMsg = string.Empty;
                try
                {
                    WOEntity WOEntity = new WOEntity()
                    {
                        WO = this.WO.ToUpper() ?? "",
                        WODescription = this.WODescription ?? "",
                        Count = Convert.ToInt32(this.WOCount),
                        PN = this.PN.ToUpper() ?? "",
                        Flow = this.Flow.ToUpper() ?? "",
                        OwnerManufacturer = this.OwnerManufacturer ?? "",
                        Actor = LogInInfo.User,
                        CustomStartSn = this.CustomStartSn ?? ""
                    };
                    this.IsVisibleLoading = Visibility.Visible;
                    retMsg = await BusinessProcess.ReleaseWO(WOEntity);

                    if (retMsg.Split('|')[0] == "OK")
                    {
                        //显示工单信息到前台页面
                        await ShowWOInfoToUIAsync();
                        MessageBox.Show(retMsg.Split('|')[1].ToString(), "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show(retMsg.Split('|')[1].ToString(), "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("释放工单时发生错误:" + ex.Message);
                }
                finally
                {
                    this.IsVisibleLoading = Visibility.Collapsed;
                    this.IsEnabledReleaseButton = false;
                    this.IsEnabledVerifyButton = true;
                }
            } /*MessageBox.Show("验证通过！");*/
            else
            {
                MessageBox.Show("信息输入有误！", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        //显示工单信息到UI页面
        private async Task ShowWOInfoToUIAsync()
        {
            DataTable dtWO = new DataTable();
            await Task.Run(() =>
            {
                dtWO = BusinessProcess.GetWOInfo(this.WO.ToUpper());
                Application.Current.Dispatcher.BeginInvoke((Action)(() =>
                {
                    WOSource = new ObservableCollection<WOEntity>();
                    for (int i = 0; i < dtWO.Rows.Count; i++)
                    {
                        WOSource.Add(
                            new WOEntity
                            {
                                WO = dtWO.Rows[i]["WO"].ToString(),
                                WODescription = dtWO.Rows[i]["WODescription"].ToString(),
                                PN = dtWO.Rows[i]["PN"].ToString(),
                                Flow = dtWO.Rows[i]["Flow"].ToString(),
                                StartSn = dtWO.Rows[i]["StartSn"].ToString(),
                                EndSn = dtWO.Rows[i]["EndSn"].ToString(),
                                Count = Convert.ToInt32(dtWO.Rows[i]["Count"] == DBNull.Value ? "0" : dtWO.Rows[i]["Count"].ToString() ?? "0"),
                                Completed = Convert.ToInt32(dtWO.Rows[i]["Completed"] == DBNull.Value ? "0" : dtWO.Rows[i]["Completed"].ToString() ?? "0"),
                                NoCompleted = Convert.ToInt32(dtWO.Rows[i]["NoCompleted"] == DBNull.Value ? "0" : dtWO.Rows[i]["NoCompleted"].ToString() ?? "0"),
                                CloseStatus = dtWO.Rows[i]["CloseStatus"].ToString(),
                                OwnerManufacturer = dtWO.Rows[i]["OwnerManufacturer"].ToString(),
                                Actor = dtWO.Rows[i]["Actor"].ToString(),
                                CreateAt = dtWO.Rows[i]["CreateAt"].ToString(),
                            });
                    }
                }));
            });
        }

        /// <summary>
        /// 查询工单信息
        /// </summary>
        private void Query()
        {
            DataTable dtWO = new DataTable();
            if (string.IsNullOrEmpty(this.PN))
            {
                MessageBox.Show("请先选择机种再点击查询", "软件温馨提示!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            dtWO = BusinessProcess.GetWOInfoByPn(this.PN.ToUpper());
            WOSource = new ObservableCollection<WOEntity>();
            for (int i = 0; i < dtWO.Rows.Count; i++)
            {
                WOSource.Add(
                    new WOEntity
                    {
                        WO = dtWO.Rows[i]["WO"].ToString(),
                        WODescription = dtWO.Rows[i]["WODescription"].ToString(),
                        PN = dtWO.Rows[i]["PN"].ToString(),
                        Flow = dtWO.Rows[i]["Flow"].ToString(),
                        StartSn = dtWO.Rows[i]["StartSn"].ToString(),
                        EndSn = dtWO.Rows[i]["EndSn"].ToString(),
                        Count = Convert.ToInt32(dtWO.Rows[i]["Count"] == DBNull.Value ? "0" : dtWO.Rows[i]["Count"].ToString() ?? "0"),
                        Completed = Convert.ToInt32(dtWO.Rows[i]["Completed"] == DBNull.Value ? "0" : dtWO.Rows[i]["Completed"].ToString() ?? "0"),
                        NoCompleted = Convert.ToInt32(dtWO.Rows[i]["NoCompleted"] == DBNull.Value ? "0" : dtWO.Rows[i]["NoCompleted"].ToString() ?? "0"),
                        CloseStatus = dtWO.Rows[i]["CloseStatus"].ToString(),
                        OwnerManufacturer = dtWO.Rows[i]["OwnerManufacturer"].ToString(),
                        Actor = dtWO.Rows[i]["Actor"].ToString(),
                        CreateAt = dtWO.Rows[i]["CreateAt"].ToString(),
                    });
            }
        }

        /// <summary>
        /// 筛选机种下拉列表框中的数据
        /// </summary>
        private void FilterPN()
        {
            IsOpenComboPNDropDown = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (isFirstFilterPN)
            {
                backupPNs = new ObservableCollection<PartNumberEntity>();
                backupPNs = PNs;
                isFirstFilterPN = false;
            }
            if (!string.IsNullOrEmpty(SearchPNText))
            {
                IEnumerable<PartNumberEntity> partNumberEntities = PNs.Where(s => s.PN.ToUpper().Contains(SearchPNText.ToUpper()));
                PNs = new ObservableCollection<PartNumberEntity>();
                foreach (var p in partNumberEntities)
                {
                    PNs.Add(p);
                }
            }
            else
            {
                PNs = backupPNs;
            }
        }

        /// <summary>
        /// 机种下拉框选项改变事件处理函数
        /// </summary>
        private void ComboPN_SelectionChangedHandler(string param)
        {
            DataTable dtFlows = new DataTable();
            DataTable dtPN = new DataTable();//机种信息
            dtFlows = BusinessProcess.GetFlowsByPN(param);
            Flows = new ObservableCollection<RoutingEntity>();
            for (int i = 0; i < dtFlows.Rows.Count; i++)
            {
                Flows.Add(new RoutingEntity { Flow = dtFlows.Rows[i]["Flow"].ToString() });
            }
            dtPN = BusinessProcess.GetPNInfo(param);
            //初始化前台页面显示的机种信息
            if (dtPN.Rows.Count > 0)
            {
                this.SnFormat = dtPN.Rows[0]["SnFormat"].ToString();
                this.UnitCode = dtPN.Rows[0]["UnitCode"].ToString();
                this.KitCount = Convert.ToInt32(dtPN.Rows[0]["KitCount"] == DBNull.Value ? "0" : dtPN.Rows[0]["KitCount"].ToString() ?? "0");
                this.PrintCopiesNum = Convert.ToInt32(dtPN.Rows[0]["PrintCopiesNum"] == DBNull.Value ? "0" : dtPN.Rows[0]["PrintCopiesNum"].ToString() ?? "0");
                this.PNType = dtPN.Rows[0]["PnType"].ToString();
            }
        }

        /// <summary>
        /// 筛选流程下拉列表框中的数据
        /// </summary>
        private void FilterFlow()
        {
            IsOpenComboRoutingDropDown = true;
            //当是第一次过滤的时候备份原始数据
            //这样是为了当不输入搜索条件时添加原始数据到列表中
            //当输入搜索条件时生成过滤集合绑定当下拉列表中
            if (isFirstFilterFlow)
            {
                backupFlows = new ObservableCollection<RoutingEntity>();
                backupFlows = Flows;
                isFirstFilterFlow = false;
            }
            if (!string.IsNullOrEmpty(SearchFlowText) && Flows != null)
            {
                IEnumerable<RoutingEntity> routingEntities = Flows.Where(s => s.Flow.ToUpper().Contains(SearchFlowText.ToUpper()));
                Flows = new ObservableCollection<RoutingEntity>();
                foreach (var f in routingEntities)
                {
                    Flows.Add(f);
                }
            }
            else
            {
                Flows = backupFlows;
            }
        }

        /// <summary>
        /// 填充机种信息到下拉列表框中
        /// </summary>
        private void FillPNsToComboBox()
        {
            #region 验证使用

            //PNs = new ObservableCollection<PartNumberEntity>();
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "MEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "SEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "REST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "BEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "AEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "OEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "NEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "MEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "REST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "TEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "WEST1-AAA" });
            //PNs.Add(new PartNumberEntity { PN = "XEST1-AAA" });

            #endregion 验证使用

            DataTable dtPNs = new DataTable();
            dtPNs = BusinessProcess.GetPNs(EnumPNType.All);
            PNs = new ObservableCollection<PartNumberEntity>();
            for (int i = 0; i < dtPNs.Rows.Count; i++)
            {
                PNs.Add(new PartNumberEntity
                {
                    PN = dtPNs.Rows[i]["PartNumber"].ToString()
                });
            }
        }

        /// <summary>
        /// 删除工单
        /// </summary>
        /// <param name="obj"></param>
        private void DeleteWO(WOEntity entity)
        {
            if (entity != null)
            {
                OnDeleteingWOAsync(entity);
            }
        }

        private async Task OnDeleteingWOAsync(WOEntity entity)
        {
            string retMsg = string.Empty;//返回的状态信息
            string[] arrayMsg = new string[2];
            retMsg = await Task.Run<string>(() =>
            {
                return BusinessProcess.EmployeeIsHaveModuleAuthority("AE"); //AE删除工单权限
            });
            arrayMsg = retMsg.Split('|');
            //Y表示有权限
            if (arrayMsg[0] == "Y")
            {
                bool isProduced = await Task.Run<bool>(() =>
                {
                    return BusinessProcess.WOIsProduced(entity.WO);
                });
                if (!isProduced)
                {
                    //确定用户是否要删除，防止误删
                    MessageBoxResult boxResult = MessageBox.Show(string.Format("确定要删除工单【{0}】吗？", entity.WO), "软件温馨提示!", MessageBoxButton.YesNo, MessageBoxImage.Question);
                    if (boxResult == MessageBoxResult.Yes)
                    {
                        retMsg = await Task.Run<string>(() =>
                        {
                            return BusinessProcess.DeleteWOInfo(entity);
                        });
                        arrayMsg = retMsg.Split('|');
                        if (arrayMsg[0] == "OK")
                        {
                            WOSource.Remove(entity);
                        }
                        else
                        {
                            MessageBox.Show("删除失败", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("此工单已经在生产中...不允许删除，如果要删除请联系管理员.谢谢！", "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show(arrayMsg[1], "软件温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }

        #region 附属方法

        /// <summary>
        /// 移除字典
        /// </summary>
        /// <param name="dics"></param>
        /// <param name="dicKey"></param>
        private void RemoveDic(Dictionary<String, String> dics, String dicKey)
        {
            dics.Remove(dicKey);
        }

        /// <summary>
        /// 添加字典
        /// </summary>
        /// <param name="dics"></param>
        /// <param name="dicKey"></param>
        private void AddDic(Dictionary<String, String> dics, String dicKey)
        {
            if (!dics.ContainsKey(dicKey)) dics.Add(dicKey, "");
        }

        #endregion 附属方法

        #endregion 方法
    }
}